package com.rw;

//import com.rw.mapper.AccountMapper123;
import com.rw.pojo.Account;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.*;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Map;

public class JuintTest {

    @BeforeClass
    public static void testBefore(){
        System.out.println("最先执行的代码");
    }

    @AfterClass
    public static void testAfter(){
        System.out.println("最后执行行的代码");
    }

    @Before
    public void before(){
        System.out.println("-----每次都要执行的代码------");
    }

    @After
    public void after(){
        System.out.println("-----每次都要结束执行的代码------");
    }

    @Test
    public void testPrint2() throws IOException {
        //创建SqlSessionFactory
        InputStream is = Resources.getResourceAsStream("mybatis-config.xml");
        SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(is);
        //创建SqlSession
        SqlSession session = factory.openSession();
        //调用查询方法
        List<Map> list  = session.selectList("com.rw.mapper.AccountMapper123.selectAll");
//        AccountMapper123 mapper = session.getMapper(AccountMapper123.class);
//        List<Map> list = mapper.selectAll();
        //关闭资源
        session.close();
        //输出结果
    }

    @Test
    public void testPrint() throws IOException {
        //创建SqlSessionFactory
        InputStream is = Resources.getResourceAsStream("mybatis-config.xml");
        SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(is);
        //创建SqlSession
        SqlSession session = factory.openSession();
        Account account =new Account("123",123.0,3);
        int x = session.insert("com.rw.mapper.AccountMapper123.insertOne",account);
        System.out.println(x);
        session.commit();
        session.close();
    }

    @Test
    public void testPrint1(){
        System.out.println("测试框架");
    }

    @Test
    @Ignore
    public void testSelectById(){
        Assert.assertTrue(1==2);
    }
}
